angular.module("app").controller("user.manageList.Ctrl", ["$scope", "$state", "User", function ($scope, $state, User) {
    $scope.search = { roleId: "", key: "" };
    $scope.canEdit = $scope.userInfo.roles.indexOf("{1}") >= 0;
    $scope.userGridConfig = {
        bindingOptions: {
            selectedRowKeys: "selectedItems",
            dataSource: "userGridConfig.dataSource"
        },
        twoWayBindingEnabled: false,
        searchPanel: {
            visible: true,
            width: 200,
            placeholder: "输入关键字进行查询"
        },
        paging: {
            pageSize: 15
        },
        groupPanel: {
            visible: true,
            emptyPanelText: "拖动列名进行分组和排序"
        },
        hoverStateEnabled: true,
        showBorders: true,
        showRowLines: true,
        rowAlternationEnabled: true,
        noDataText: "没有数据",
        columns: [{
            dataField: "manageName",
            alignment: "center",
            caption: "用户名"
        }, {
                dataField: "phone",
                alignment: "center",
                caption: "手机号"
            }, {
                dataField: "nickName",
                alignment: "center",
                caption: "昵称"
            }, {
                dataField: "roles",
                alignment: "center",
                customizeText: function (cellInfo) {
                    var str = "";
                    cellInfo.value.split(",").forEach(function (item) {
                        var tmp = $scope.$parent.roleDict[item.replace(/[^\d]+/g, "")];
                        if (tmp) {
                            str += tmp.text + ";"
                        }
                    });
                    return str;
                },
                caption: "权限"
            }, {
                dataField: "status",
                alignment: "center",
                cellTemplate: "statusCellTemplate",
                width: 60,
                caption: "状态"
            }, {
                dataField: "operation",
                alignment: "center",
                cellTemplate: "operationCellTemplate",
                caption: "操作"
            }]
    };
    $scope.getUserList = function () {
        User.getList({}, $scope.search, function (data) {
            if (data.statusCode == 0) {
                $scope.userGridConfig.dataSource = data.data;
            }
            else if (data.statusCode == -4) {
                alert("用户没有权限");
            } else {
                alert(data.statusMessage)
            }
        })
    };
    $scope.showManagerInfo = function (manage) {
        $state.go("home.user.manageInfo", { manageInfo: manage, manageId: manage.manageId, type: "view" })
    }
    $scope.createManagerInfo = function () {
        $state.go("home.user.manageInfo", { type: "create" })
    };
    $scope.editManagerInfo = function (manage) {
        $state.go("home.user.manageInfo", { manageInfo: manage, manageId: manage.manageId, type: "edit" })
    };
    $scope.getUserList();
}]);